<template>
  <el-dialog
    title="直播信息"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    class="dialog"
    width="656px"
  >
    <div class="title">步骤一：下载直播工具</div>
    <div class="relayArea">
      <el-input
        ref="inputToCopy"
        v-model="liveSrc"
        readonly
      ></el-input>
      <el-button type="primary" @click="openLink(liveSrc)">打开链接</el-button>
    </div>
    <div class="title">步骤二：输入自己的姓名、输入直播密码</div>
    <div class="relayArea">
      <el-input
        ref="inputToCopy"
        v-model="livePassword"
        readonly
      ></el-input>
      <el-button type="primary" @click="copyToClipboard(livePassword)">复制密码</el-button>
    </div>
    <div></div>
  </el-dialog>
</template>

<script>
import { getTeachLiveAddress } from '@/api/teach';
import { copyToClipboard } from '@/utils'

export default {
  name: 'LiveInfo',
  props: {
    objectId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      dialogVisible: false,
      liveSrc: '',
      livePassword: '',
    };
  },
  computed: {
  },
  mounted() {
    this.getData()
  },
  methods: {
    // 获取
    async getData() {
      try {
        let params = {
          objectId: this.objectId,
        };
        const resData = await getTeachLiveAddress(params);
        this.liveSrc = resData?.address;
        this.livePassword = resData?.password;
      } catch (error) {
        console.error(error);
      }
    },
    // 复制到粘贴板
    copyToClipboard(text) {
      copyToClipboard(text);
    },
    // 打开链接
    openLink(url) {
      window.open (url, "_blank");
    }
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  ::v-deep .el-dialog {
    border-radius: 8px;
  }
  ::v-deep .el-input__inner {
    border-radius: 0;
  }
  ::v-deep .el-button {
    border-radius: 0;
  }
  ::v-deep .el-dialog__body {
    padding: 20px 50px;
    box-sizing: border-box;
  }
  .title{
    font-size: 16px;
    font-weight: 600;
    color: $text-color;
    margin-bottom: 20px;
  }
  .relayArea {
    display: flex;
    margin-top: 20px;
    margin-bottom: 20px;
  }
}
</style>
